﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class hlAdmin_admin_login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, ImageClickEventArgs e)
    {

        string userName = txtUsername.Text.Trim();
        string userPass = txtUserpass.Text.Trim();
        BZZ.DataAcess woker = new BZZ.DataAcess();
        userName = LIB.Filter.inputFilter(userName);
        userPass = LIB.Filter.inputFilter(userPass);
        userPass = (new BZZ.CommonFunctions()).StringToMD5Hash(userPass);
        string sql = "select * from admin where username='" + userName + "' and userpass='" + userPass + "'";
        DataSet dset = woker.Execute(sql);
        if (dset == null && dset.Tables[0].Rows.Count < 1)
        {
            LIB.JsWrite.AlertAndGoback(this, "登录失败，请重新输入。");
        }
        else
        {
            this.Session["admin"] = "yes";
            HttpCookie cookie = new HttpCookie("admin");
            cookie.Value = "yes";
            cookie.Expires = DateTime.Now.AddHours(2);
            Response.Cookies.Add(cookie);
            //Response.Cookies["admin"].Expires = DateTime.Now.AddHours(3);
            LIB.JsWrite.AlertAndGo(this, "登录成功。", "admin_admin.aspx");
        }
    }
}
